# - Config file for the @component_pkg_name@ component
#
# This should only be invoked by @PKG_NAME@-config.cmake.
#
# To load this component into your project, use:
# find_package(@PKG_NAME@ COMPONENTS @component_name@)
#
# This creates the following targets:
#
#   Component library target                - @import_target_name@
#   Alternative target name                 - @simple_import_name@
#   Core library + all requested components - @gz_namespace@requested
#
# Use target_link_libraries() to link your library or executable to one of the
# above targets.
#
# We also provide the following variable for backwards compatibility, but use of
# this is discouraged:
#
#   @component_pkg_name@_LIBRARY  - Component library (actually contains @simple_import_name@)
#
# We will also set @component_pkg_name@_FOUND to indicate that the component was found.
#
################################################################################

# We explicitly set the desired cmake version to ensure that the policy settings
# of users or of toolchains do not result in the wrong behavior for our modules.
# Note that the call to find_package(~) will PUSH a new policy stack before
# taking on these version settings, and then that stack will POP after the
# find_package(~) has exited, so this will not affect the cmake policy settings
# of a caller.
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)

if(@component_pkg_name@_CONFIG_INCLUDED)
  return()
endif()
set(@component_pkg_name@_CONFIG_INCLUDED TRUE)

if(NOT @component_pkg_name@_FIND_QUIETLY)
  message(STATUS "Looking for @component_pkg_name@ -- found version @PROJECT_VERSION_FULL@")
endif()

@PACKAGE_INIT@

# Get access to the find_dependency utility
include(CMakeFindDependencyMacro)

# Find gz-cmake, because we need its modules in order to find the rest of
# our dependencies.
find_dependency(gz-cmake@GZ_CMAKE_VERSION_MAJOR@)

# Set the REQUIRED flag for the find_package(~) calls on this component's
# dependencies.
if(@component_pkg_name@_FIND_REQUIRED)
  set(gz_package_required REQUIRED)
else()
  set(gz_package_required "")
endif()

# Set the QUIET flag for the find_package(~) calls on this component's
# dependencies.
if(@component_pkg_name@_FIND_QUIETLY)
  set(gz_package_quiet QUIET)
else()
  set(gz_package_quiet "")
endif()

# --------------------------------
# Find the dependencies that are specific to this component (if nothing is
# below, then the component has no additional dependencies). We use
# find_package(~) instead of find_dependency(~) here so that we can support
# COMPONENT arguments.
#
# TODO: When we migrate to cmake-3.9+, change these to find_dependency(~),
#       because at that point the find_dependency(~) function will support
#       the COMPONENT argument.
if(NOT @component_pkg_name@_FIND_QUIETLY)
  message(STATUS "Searching for dependencies of @component_pkg_name@")
endif()
@component_cmake_dependencies@
# --------------------------------

if(NOT TARGET @import_target_name@)
  include("${CMAKE_CURRENT_LIST_DIR}/@target_output_filename@")

  # Create a simplified imported target name for the @component@ library.
  # You can link to this target instead of the @component@ library.
  add_library(@simple_import_name@ INTERFACE IMPORTED)
  set_target_properties(@simple_import_name@ PROPERTIES
    INTERFACE_LINK_LIBRARIES "@import_target_name@")
  # Note: In a future version of cmake, we can replace this with an ALIAS target

endif()

# Create the "requested" target if it does not already exist
if(NOT TARGET @gz_namespace@requested)
  add_library(@gz_namespace@requested INTERFACE IMPORTED)
endif()

# Link the @component@ library to the "requested" target
get_target_property(gz_requested_components @gz_namespace@requested INTERFACE_LINK_LIBRARIES)
if(NOT gz_requested_components)
  set_target_properties(@gz_namespace@requested PROPERTIES
    INTERFACE_LINK_LIBRARIES "@import_target_name@")
else()
  set_target_properties(@gz_namespace@requested PROPERTIES
    INTERFACE_LINK_LIBRARIES "${gz_requested_components};@import_target_name@")
endif()

set(@component_pkg_name@_LIBRARY @import_target_name@)

# This macro is used by gz-cmake to automatically configure the pkgconfig
# files for Gazebo projects.
gz_pkg_config_entry(@component_pkg_name@ "@component_pkg_name@")
